<template>
  <div class="role-box">
    <div class="justify-start">
      <el-input
        v-model="keyword"
        placeholder="搜索成员姓名"
        style="width: 260px"
      ></el-input>
      <span class="add-btn" @click="openAddAdminModel()"
        ><i class="el-icon-plus" />添加成员</span
      >
    </div>
    <el-table
      max-height="734"
      :data="tableData"
      style="
        width: 100%;
        margin-top: 12px;
        background-color: #303136;
        color: #ffff;
      "
      :border="false"
    >
      <el-table-column prop="nickname" label="用户名"> </el-table-column>
      <el-table-column prop="username" label="账号"> </el-table-column>
      <el-table-column prop="postCode" label="工号"> </el-table-column>
      <!-- <el-table-column prop="unit" label="所属单位"> </el-table-column> -->
      <el-table-column prop="deptName" label="所属部门"> </el-table-column>
      <el-table-column prop="opration" label="操作">
        <template slot-scope="scope">
          <el-popconfirm
            title="确认删除此用户吗？"
            @confirm="delRoleUnbindAdmin(scope.row)"
          >
            <span class="opration-btn" slot="reference">删除</span>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      :append-to-body="true"
      title="新增用户"
      :visible.sync="rolevisible"
      width="35%"
    >
      <add-admin-to-role
        v-if="rolevisible"
        :roleId="roleId"
        @onClose="closeRoleModel"
      ></add-admin-to-role
    ></el-dialog>
  </div>
</template>

<script>
import AddAdminToRole from "./AddAdminToRole.vue";
import { getRoleAdminList, roleUnbindAdmin } from "@/api/auth";
export default {
  props: ["roleId"],
  components: {
    AddAdminToRole,
  },
  data() {
    return {
      tableData: [],

      keyword: "",
      rolevisible: false,
    };
  },

  mounted() {
    this.getRoleAdminList();
  },

  methods: {
    async getRoleAdminList() {
      let res = await getRoleAdminList({
        roleId: this.roleId,
      });
      if (res.code == 200) {
        this.tableData = res.data;
      }
    },
    closeRoleModel(e) {
      this.rolevisible = false;
      if (e.isClose) {
        this.getRoleAdminList();
      }
    },
    openAddAdminModel() {
      this.rolevisible = true;
    },

    //删除
    async delRoleUnbindAdmin(data) {
      let res = await roleUnbindAdmin({
        userIds: `${data.id}`,
        roleId: this.roleId,
      });
      if (res.code == 200) {
        this.getRoleAdminList();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.role-box {
  width: 100%;
  height: 100%;

  .opration-btn {
    display: inline-block;
    color: #fff;
    background: #40414d;
    border-radius: 4px;
    cursor: pointer;
    padding: 6px 12px;
    margin-top: 10px;
    margin-right: 10px;
  }

  .add-btn {
    width: 112px;
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #17181a;
    background: #5cfbff;
    border-radius: 4px;
    margin-left: 16px;
    cursor: pointer;
  }
}
</style>